<template>
  <div>
    <el-card>
      <div class="box_main_accordion">
        <accordion v-for="(task,taskIndex) in tasks" :key="task.taskId">
          <accordionTitle class="TimelineTitle-first">
            <div class="TimelineTitle-first-lf">
              <i class="el-icon-star-on"></i>
              {{task.name}}
            </div>
            <div>
              <el-button type="primary" size="mini" icon="el-icon-edit" @click="addGroup(task)">新增组</el-button>
              <i :class="{'el-icon-arrow-down':!task.isShow,'el-icon-arrow-up':task.isShow}" @click="task.isShow = !task.isShow"></i>
            </div>
          </accordionTitle>
          <div class="TimelineItem-first">
            <el-collapse-transition>
              <ul class="TimelineItem-UL" v-show="!task.isShow">
                <li class="transition-box TimelineItem_firtsItem" v-for="(group,groupIndex) in task.groups" :key="group.key">
                  <div class="TimelineItem-first-lf">
                    <div class="TimelineItem-first-lf-nl">
                      <i class="el-icon-location" style="marginRight:5px;"></i>{{group.dept.label}}
                    </div>
                    <div class="TimelineItem-first-lc">
                      <ul>
                        <li class="TimelineItem-first-lcItme" v-for="role in group.roles" :key="role.name">{{role.zh}}</li>
                      </ul>
                    </div>
                  </div>
                  <div class="TimelineItem-first-lr">
                    <el-button size="mini" type="primary" @click="editGroup(group)" icon="el-icon-edit" plain></el-button>
                    <el-button size="mini" type="danger" @click="handleDelete(taskIndex,groupIndex)" icon="el-icon-delete" plain></el-button>
                  </div>
                </li>
              </ul>
            </el-collapse-transition>
          </div>
        </accordion>
      </div>
    </el-card>
  </div>
</template>
<script>
  import accordion from "./accordion/accordion.vue";
  import accordionTitle from "./accordion/accordionTitle.vue";

  export default {
    data() {
      return {
      };
    },
    props: ["tasks"],
    components: {
      accordion,
      accordionTitle
    },
    watch: {},
    computed: {},
    methods: {
      addGroup(task) {
        let tempGroup = {
          deptIds: [],
          roles: [],
          dept: {
            id: null,
            label: null
          }
        }
        let vo = {
          task: task,
          tempGroup: tempGroup
        }
        this.$emit("transGroup", vo);
      },
      editGroup(group) {
        let vo = {
          task: null,
          tempGroup: group
        }
        this.$emit("transGroup", vo);
      },
      handleDelete(taskIndex, groupIndex) {
        this.tasks[taskIndex].groups.splice(groupIndex, 1)
      }
    },
    filter: {
      indexFn(val) {
        val = val + 1;
        if (val) {
          return val;
        } else {
          return "";
        }
      }
    }
  };
</script>
<style scoped>
  .TimelineItem-UL {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .TimelineTitle-first-lf {
    width: 50%;
    height: 22px;
    line-height: 22px;
    overflow: hidden;
    font-size: 16px;
    color: #409eff;
  }

  .TimelineItem-first-lcItme {
    border-radius: 3px;
    overflow: hidden;
    padding: 5px;
    margin-right: 7px;
    margin-bottom: 3px;
    margin-top: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 17px;
    color: #333;

  }

  .TimelineItem-first-lc ul {
    display: flex;
    flex-wrap: wrap;
  }

  .TimelineItem-first-lc {
    min-height: 40px;
    display: flex;
    flex-wrap: wrap;
    overflow: hidden;
    width: 70%;
    margin-left: 2%;
    /* border: 1px solid red; */
  }

  .TimelineItem-first-lf-nl {
    display: flex;
    align-items: center;
    width: 30%;
  }

  .TimelineItem-first-lf {
    font-size: 15px;
    color: #409eff;
    text-align: left;
    padding-top: 7px;
    padding-bottom: 7px;
    display: flex;
    width: 90%;
  }

  .TimelineItem-first {
    width: 80%;
    margin-left: 40px;
  }

  .TimelineItem-first-lr {
    display: flex;
    align-items: center;
    min-width: 120px;
  }

  .TimelineItem_firtsItem {
    padding-top: 5px;
    padding-bottom: 4px;
    min-height: 50px;
    margin-left: 15px;
    width: calc(100% - 15px);
    /* border-bottom: 1px solid #ccc; */
    display: flex;
    align-items: center;
    justify-content: space-between;
    overflow: hidden;
  }

  .TimelineItem_firtsItem:last-child {
    border-bottom: none;
  }

  .TimelineTitle-senoud {
    display: flex;
    justify-content: space-between;
    height: 45px;
    border-bottom: 1px solid #aaa;
  }

  .box_main_accordion .el-icon-arrow-down,
  .box_main_accordion .el-icon-arrow-up {
    cursor: pointer;
    font-size: 20px;
    margin-left: 15px;
  }

  .TimelineTitle-first {
    display: flex;
    justify-content: space-between;
    color: #409eff;
    height: 45px;
    border-bottom: 2px solid #ccc;
  }

  .box_main_accordion .el-icon-star-on {
    color: #409eff;
    font-size: 15px;
  }

  .box_main_accordion {
    width: 100%;
    overflow: hidden;
    background-color: #fff;
    padding-top: 5px;
    margin-left: 15px;
  }
</style>